import { defineStore } from 'pinia';

export const useUserStore = defineStore('user', {
  state: () => ({
    userInfo: JSON.parse(localStorage.getItem('userInfo')) || null, // 从 LocalStorage 初始化
  }),
  actions: {
    setUserInfo(info) {
      this.userInfo = info;
      localStorage.setItem('userInfo', JSON.stringify(info)); // 存储到 LocalStorage
    },
    clearUserInfo() {
      this.userInfo = null;
      localStorage.removeItem('userInfo'); // 清除 LocalStorage
    },
  },
});